package com.axter.libs.photo.previewphoto;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.Fragment;

import com.axter.libs.photo.display.IPhotoDisplayInterface;

import java.util.ArrayList;

/**
 * Created by axter on 2016/10/13.
 */

public class PreviewPhotoIntent extends Intent {
    private ArrayList<String> images;
    private ArrayList<Integer> checked;
    private int position;
    private String photoDisplayInterfacePath;

    public PreviewPhotoIntent(Context packageContext, Class<? extends PreviewPhotoBaseActivity> clazz) {
        super(packageContext, clazz);
    }

    public PreviewPhotoIntent(Context packageContext, int type) {
        super(packageContext, getClass(type));
    }

    public PreviewPhotoIntent setImages(ArrayList<String> _images) {
        images = _images;
        return this;
    }

    public PreviewPhotoIntent setPosition(int _position) {
        position = _position;
        return this;
    }

    /**
     * 0 未选中
     *
     * @param _checked
     * @return
     */
    public PreviewPhotoIntent setChecked(ArrayList<Integer> _checked) {
        checked = _checked;
        return this;
    }

    public PreviewPhotoIntent setPhotoDisplayInterface(Class<? extends IPhotoDisplayInterface> clazz) {
        this.photoDisplayInterfacePath = clazz.getName();
        return this;
    }

    private static Class getClass(int type) {
        if (type == PreviewPhotoBaseActivity.EXTRA_TYPE_DEL) {
            return PreviewPhotoDeleteActivity.class;
        } else if (type == PreviewPhotoBaseActivity.EXTRA_TYPE_CHECK) {
            return PreviewPhotoCheckActivity.class;
        } else if (type == PreviewPhotoBaseActivity.EXTRA_TYPE_PREVIEW) {
            return PreviewPhotoPreviewActivity.class;
        } else {
            return PreviewPhotoBaseActivity.class;
        }
    }

    private void handleData() {
        putStringArrayListExtra(PreviewPhotoBaseActivity.EXTRA_IMAGE_PATHS, images);
        putExtra(PreviewPhotoBaseActivity.EXTRA_POSITION, position);
        putIntegerArrayListExtra(PreviewPhotoBaseActivity.EXTRA_CHECK, checked);
        putExtra(PreviewPhotoBaseActivity.EXTRA_DISPLAY_INTERFACE, photoDisplayInterfacePath);
    }

    public void startActivity(Context context) {
        handleData();
        context.startActivity(this);
    }

    public void startActivity(Activity activity, int requestCode) {
        handleData();
        activity.startActivityForResult(this, requestCode);
    }

    public void startActivity(Fragment fragment, int requestCode) {
        handleData();
        fragment.startActivityForResult(this, requestCode);
    }

    public void startActivity(android.app.Fragment fragment, int requestCode) {
        handleData();
        fragment.startActivityForResult(this, requestCode);
    }
}
